using UnityEngine;

public class FollowTheMouse : MonoBehaviour
{
	public float maxSpeed;

	public float moveSpeed;

	public float turnSpeed;

	public float origParticleMinSize;

	public float origParticleMaxSize;

	public float origParticleLocalYSpeed;

	public ParticleSystem emitter;

	private void Start()
	{
		origParticleMinSize = emitter.main.startSize.constantMin;
		origParticleMaxSize = emitter.main.startSize.constantMax;
		origParticleLocalYSpeed = emitter.main.startSpeed.constant;
	}

	private void Update()
	{
		Vector3 mousePosition = Input.mousePosition;
		mousePosition.z = 1f;
		Vector3 vector = Camera.main.ScreenToWorldPoint(mousePosition);
		Vector3 vector2 = vector - base.transform.position;
		if (vector2.magnitude > 1f)
		{
			GetComponent<Rigidbody>().velocity += vector2 * Time.deltaTime * moveSpeed;
			if (Mathf.Abs(Vector3.Dot(base.transform.right * -1f, vector2.normalized)) > 0.01f)
			{
				GetComponent<Rigidbody>().angularVelocity = new Vector3(0f, 0f, Vector3.Dot(base.transform.right * -1f, vector2.normalized) * turnSpeed);
			}
		}
		if (GetComponent<Rigidbody>().velocity.magnitude > maxSpeed)
		{
			GetComponent<Rigidbody>().velocity = GetComponent<Rigidbody>().velocity.normalized * maxSpeed;
		}
		//emitter.minSize = origParticleMinSize * (GetComponent<Rigidbody>().velocity.magnitude / maxSpeed);
		//emitter.maxSize = origParticleMaxSize * (GetComponent<Rigidbody>().velocity.magnitude / maxSpeed);
		//emitter.localVelocity = new Vector3(0f, origParticleLocalYSpeed * (GetComponent<Rigidbody>().velocity.magnitude / maxSpeed), 0f);
	}
}
